package com.队列;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 队列实现
 */
public class Queue {
  private List<Integer> data;

  private int start;
  public Queue(){
    data = new ArrayList<>();
    start = 0;
  }

  /**
   * 入队
   * @param x
   * @return
   */
  public boolean endQueue(int x){
    data.add(x);

    return true;
  }

  /**
   * 出队
   * @return
   */
  public boolean deQueue(){
    if(isEmpty()){
      return false;
    }
     data.remove(start);
    return true;
  }

  /**
   * 队头
   * @return
   */
  public int font(){
    return  data.get(start);
  }
  public boolean isEmpty(){
    return start >= data.size();
  }

  @Override
  public String toString() {
    StringBuilder builder = new StringBuilder();
    for(int i : this.data){
      builder.append(i+" ");
    }

    System.out.println("Queue{" +
            builder.toString() +
            '}');
    return "Queue{" +
           builder.toString() +
            '}';
  }

  public static void main(String[] args) {
    Queue queue = new Queue();


//    queue.endQueue(2);
//    queue.endQueue(3);
//    queue.endQueue(4);
//    queue.endQueue(5);
//    queue.toString();
//    System.out.println(queue.font());
//    queue.deQueue();
//    System.out.println(queue.font());
    int i =  0;
    while (true){
     // System.out.println("出队输入0");
      //System.out.println("结束输入-1");
      System.out.println("输入入队数字：");
      i = new Scanner(System.in).nextInt();
     if(i == -1){
       System.out.println("结束队列");
       break;
     }
     if(i==0){
       if(!queue.deQueue()){
         System.out.println("空队列");
       }else{
         queue.toString();
       }

     }
     else{
       queue.endQueue(i);
       queue.toString();

     }

    }
  }
}

